"""
业务日志 | 接口
"""

from fastapi import (
    APIRouter,
    Depends,
)

import utils.enum_utils as enum
from biz import biz_log_file_biz
from components.audit_log import audit
from components.depends import admin_required
from components.global_param import get_user_id
from components.logger import log
from components.response import OKWithDataResponse
from models.request import (
    BizLogFileListRequest,
    BizLogListRequest,
)
from models.response import (
    BizLogFileListResponse,
    BizLogListResponse,
)
from models.vo import (
    BizLogFileListPage,
    BizLogListPage,
)

biz_log_file_router: APIRouter = APIRouter(prefix="/biz_log_file")
""" 业务日志文件 路由 """

biz_log_router: APIRouter = APIRouter(prefix="/biz_log")
""" 业务日志 路由 """


@biz_log_file_router.get(
    path="/",
    summary="业务日志文件 | 列表",
    response_model=BizLogFileListResponse,
    dependencies=[Depends(admin_required)],
)
@audit(
    model=enum.Model.BIZ_LOG_FILE,
    operation=enum.ModelOperation.LIST,
)
async def biz_log_file_list(request: BizLogFileListRequest = Depends(BizLogFileListRequest.from_query)) -> OKWithDataResponse:
    vo: BizLogFileListPage = biz_log_file_biz.BizLogFileGetter.list(request)
    log.info(f"[业务日志文件][列表] user_id: {get_user_id()}")

    return OKWithDataResponse(vo)


@biz_log_router.get(
    path="/",
    summary="业务日志 | 列表",
    response_model=BizLogListResponse,
    dependencies=[Depends(admin_required)],
)
@audit(
    model=enum.Model.BIZ_LOG,
    operation=enum.ModelOperation.LIST,
)
async def biz_log_list(request: BizLogListRequest = Depends(BizLogListRequest.from_query)) -> OKWithDataResponse:
    vo: BizLogListPage = biz_log_file_biz.BizLogGetter.list(request)
    log.info(f"[业务日志][列表] user_id: {get_user_id()}")

    return OKWithDataResponse(vo)
